﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZK.Models;
using ZK.Common;

namespace ZK.InterfaceServer
{
    public class LoginApiServer
    {
        private static readonly string LoginCN = "login/";
        private static readonly string LoginAN = LoginCN + "login";//登录


        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="loginUserM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<LoginReceiveM> Login(LoginUserM loginUserM)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("username", loginUserM.username);
            keyValuePairs.Add("password", loginUserM.password);
            string url = InterfaceExecute.GetUrl(LoginAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("Login " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<LoginReceiveM>>(ret);

        }
    }
}
